package com.useeinfo.oa.modules.repair.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * @Auther: xudong.sun
 * @Date: 2018/12/26 16:53
 * @Description:维修紧急程度表
 */
@Entity
@Table(name = "repair_level")
public class RepairLevel extends SuperClassEntity<RepairLevel> {

    /**
     * 需求完成距创建时间（分钟）
     */
    private int finishTime;


    /**
     * 需求到场距创建时间（分钟）
     */
    private int presenceTime;

    /**
     * 程度名称
     */
    private String grade;

    /**
     * Dashboard显示颜色：编号YELLOW RED，为空为GREEN
     */
    private String color;

    /**
     * 关联企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public int getFinishTime() {
        return finishTime;
    }

    public void setFinishTime(int finishTime) {
        this.finishTime = finishTime;
    }

    public int getPresenceTime() {
        return presenceTime;
    }

    public void setPresenceTime(int presenceTime) {
        this.presenceTime = presenceTime;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public JSONObject toJSONObject(){
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("grade", StringConverters.null2String(getGrade()));
        jsonObject.put("finishTime",StringConverters.null2Int(getFinishTime()));
        jsonObject.put("presenceTime",StringConverters.null2Int(getPresenceTime()));
        jsonObject.put("enterpriseName",getEnterprise() == null ? "" : StringConverters.null2String(getEnterprise().getEnterpriseName()));
        return jsonObject;
    }

}
